'''
空调温度变化器
计算费用
调度策略
'''
import sys 
import os 
sys.path.append(os.path.abspath("."))

from instance.settings import Hot_MaxTemp,Hot_MinTemp,Cold_MaxTemp,Cold_MinTemp,Mode,FeeRate
__all__=['AirTemp','Charge']

def AirTemp(CurrentRoomTemp,TargetTemp,Wind,TimeStamp=1):

    '''Mode:Cold(16-24度)、Hot(22-28度)'''
    if int(Wind) == 3:
        WindSpeed = 1/60
    elif int(Wind) == 2 :
        WindSpeed = 1/120
    elif int(Wind) == 1:
        WindSpeed = 1/180
    else:
        assert "Wind out of limit!" 

    if Mode == 'Hot':
        MaxTemp = Hot_MaxTemp
        MinTemp = Hot_MinTemp
        if TargetTemp > MaxTemp:
            TargetTemp = MaxTemp
        if TargetTemp < MinTemp:
            TargetTemp = MinTemp            
        NewTemp = min(CurrentRoomTemp + WindSpeed*TimeStamp,TargetTemp)
    else:
        MaxTemp = Cold_MaxTemp
        MinTemp = Cold_MinTemp
        if TargetTemp > MaxTemp:
            TargetTemp = MaxTemp
        if TargetTemp < MinTemp:
            TargetTemp = MinTemp            
        NewTemp = max(CurrentRoomTemp - WindSpeed*TimeStamp,TargetTemp)

    return NewTemp

def Charge(CurrentRoomTemp,NewTemp):
    '''计算费用'''
    fee = abs(CurrentRoomTemp-NewTemp)*FeeRate
    return fee

if __name__=="__main__":
    CurrentRoomTemp = 20
    TargetTemp = 25
    NewTemp = AirTemp(20,25,1)
    print(NewTemp)
    fee = Charge(CurrentRoomTemp,NewTemp)
    print(fee)